-- @owner: opentestcase023
-- @date: 2022/02/24
-- @testpoint: 在视图中插入数据时使用触发器函数替换触发条件

--step1:建表;expect:成功
drop table if exists t_trigger_src_56 cascade;
create table t_trigger_src_56(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:在视图中插入数据时使用触发器函数替换触发条件;expect:成功 插入数据为5,6,7
create or replace view t_trigger_src_56_view1 as select * from t_trigger_src_56;
create or replace function insert_func()
returns trigger as $$
begin
insert into t_trigger_src_56 values(5,6,7);
return new;
end;
$$language plpgsql;
/
drop trigger if exists insert_trigger_1 on t_trigger_src_56_view1;
create trigger insert_trigger_1
instead of insert on t_trigger_src_56_view1
for each row
execute procedure insert_func();
/
select * from t_trigger_src_56 order by id1;
insert into t_trigger_src_56_view1 values(1,1,1),(2,2,2),(3,3,3);
select * from t_trigger_src_56 order by id1;
select * from t_trigger_src_56_view1 order by id1;

--step3:清理环境;expect:成功
drop trigger if exists insert_trigger_1 on t_trigger_src_56_view1;
drop table if exists t_trigger_src_56 cascade;
drop view if exists t_trigger_src_56_view1;
drop function if exists insert_func;